package br.urca.impl;

import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.DisciplinaGradeDAO;
import br.urca.model.DisciplinaGrade;

@Transactional
public class JPADisciplinaGradeDAO implements DisciplinaGradeDAO {
	
	private EntityManager manager;
	
	public JPADisciplinaGradeDAO() {
		this(null);
	}
	
	@Inject
	public JPADisciplinaGradeDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public List<DisciplinaGrade> getListDisciplinasGrade(String codCurso,
			String codHabilitacao, String grade, List<String> listAprovadas) {
		try {
			return this.manager
					.createQuery(
							"SELECT d FROM DisciplinaGrade d "
									+ "WHERE d.id.codCurso = :codcurso "
									+ "AND d.id.codHabilitacao = :codhab "
									+ "AND d.id.grade = :grade "
									+ "AND d.id.codDisciplina not in (:disciplinas) ",
							DisciplinaGrade.class)
					.setParameter("codcurso", codCurso)
					.setParameter("codhab", codHabilitacao)
					.setParameter("grade", grade)
					.setParameter("disciplinas", listAprovadas).getResultList();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
